﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data;

namespace BAL
{
    public partial class AbanINStock : Form
    {
        private LoginService.BarcodeJudgeServices bjs = new BAL.LoginService.BarcodeJudgeServices();
        public string key = "";
        public string FBillNo = "";
        public string FEntryID = "";
        public string FSku = "";
        public string StickLen = "";
        public string FQty = "";
        public string Fdate = "";
        public string Fry = "";
        private string ID;
              

        public AbanINStock()
        {
            InitializeComponent();
        }

        public AbanINStock(string _ID)
        {
            InitializeComponent();
            this.ID = _ID;
        }

        private void AbanINStock_Load(object sender, EventArgs e)
        {
            DataGridStyle();
            BinData();
        }

        private void BinData()
        {
            DataSet ds = bjs.GetAbanINStockList();
            DataTable dt = new DataTable();

            dt = ds.Tables[0];
            //if (dt.Rows.Count <= 0)
            //{
            //    return;
            //}
            //else
            //{
                dataGrid1.DataSource = dt;
            //}
        }

        private void DataGridStyle()
        {
            DataGridTableStyle dts = new DataGridTableStyle();
            dataGrid1.TableStyles.Clear();
            dts.MappingName = "AbanINStock";

            DataGridTextBoxColumn cl1=new DataGridTextBoxColumn();
            cl1.HeaderText = "序号";
            cl1.MappingName = "Num";
            cl1.Width = 40;
            dts.GridColumnStyles.Add(cl1);

            DataGridTextBoxColumn cl2 = new DataGridTextBoxColumn();
            cl2.HeaderText = "入库单号";
            cl2.MappingName = "FBillNo";
            cl2.Width = 110;
            dts.GridColumnStyles.Add(cl2);

            DataGridTextBoxColumn cl3 = new DataGridTextBoxColumn();
            cl3.HeaderText ="开单时间";
            cl3.MappingName = "Fdate";
            cl3.Width = 80;
            dts.GridColumnStyles.Add(cl3);

            DataGridTextBoxColumn cl4 = new DataGridTextBoxColumn();
            cl4.HeaderText = "开单人";
            cl4.MappingName = "NAME";
            cl4.Width = 50;            
            dts.GridColumnStyles.Add(cl4);        

             DataGridTextBoxColumn cl5= new DataGridTextBoxColumn();
             cl5.HeaderText = "总数量";
             cl5.MappingName = "total";
             cl5.Width = 40;
             dts.GridColumnStyles.Add(cl5);

             DataGridTextBoxColumn cl6 = new DataGridTextBoxColumn();
             cl6.HeaderText = "剩余数量";
             cl6.MappingName = "leftQty";
             cl6.Width = 40;
             dts.GridColumnStyles.Add(cl6);

            DataGridTextBoxColumn cl7 = new DataGridTextBoxColumn();
            cl7.HeaderText = "FSku";
            cl7.MappingName = "FSku";
            cl7.Width = 150;
            dts.GridColumnStyles.Add(cl7);
        
            DataGridTextBoxColumn cl8 = new DataGridTextBoxColumn();
            cl8.HeaderText = "物料名";
            cl8.MappingName = "FItemName";
            cl8.Width = 110;
            dts.GridColumnStyles.Add(cl8);

            DataGridTextBoxColumn cl9 = new DataGridTextBoxColumn();
            cl9.HeaderText = "属性名";
            cl9.MappingName = "AttrValue";
            cl9.Width = 110;
            dts.GridColumnStyles.Add(cl9);

            DataGridTextBoxColumn cl10 = new DataGridTextBoxColumn();
            cl10.HeaderText = "根长";
            cl10.MappingName = "StickLen";
            cl10.Width = 40;
            dts.GridColumnStyles.Add(cl10);

            DataGridTextBoxColumn cl11 = new DataGridTextBoxColumn();
            cl11.HeaderText = "米数";
            cl11.MappingName = "FQty";
            cl11.Width = 40;
            dts.GridColumnStyles.Add(cl11);

            
            dataGrid1.TableStyles.Add(dts);

        }
               

        private void dataGrid1_CurrentCellChanged(object sender, EventArgs e)
        {
            DataGrid dataGrid1 = sender as DataGrid;
            int index = ((DataGrid)sender).CurrentCell.RowNumber;
            if (((DataTable)(dataGrid1.DataSource)).Rows.Count > 0)
            {
                ((DataGrid)sender).Select(index);
            }
            
                
            FBillNo = ((DataTable)(dataGrid1.DataSource)).Rows[index]["FBillNo"].ToString();
            FEntryID = ((DataTable)(dataGrid1.DataSource)).Rows[index]["FEntryID"].ToString();
            FSku = ((DataTable)(dataGrid1.DataSource)).Rows[index]["FSku"].ToString();
            StickLen = ((DataTable)(dataGrid1.DataSource)).Rows[index]["StickLen"].ToString();
            FQty = ((DataTable)(dataGrid1.DataSource)).Rows[index]["FQty"].ToString();
            Fdate = ((DataTable)(dataGrid1.DataSource)).Rows[index]["Fdate"].ToString();
            Fry = ((DataTable)(dataGrid1.DataSource)).Rows[index]["Fry"].ToString();

        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (FBillNo == null || FBillNo == "")
            {
                MessageBox.Show("请选择要完成的订单!", "警告！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button3);
            }
            else
            {
                DialogResult dr = MessageBox.Show("是否完成订单： " + FBillNo + " ？","提示！",MessageBoxButtons.YesNo,MessageBoxIcon.Asterisk,MessageBoxDefaultButton.Button3);
                if (dr == DialogResult.Yes)
                {
                    string txt = "";
                    bool lb = bjs.FinishAbanINStock(FBillNo, FEntryID);
                    if (lb)
                    {
                        DataGridStyle();
                        BinData();
                    }
                    else
                    {
                        MessageBox.Show("完成订单错误！ " + txt, "警告！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button3);
                    }
                }
                else
                {
                    return;
                }
            
            }
        }
        private void button4_Click(object sender, EventArgs e)
        {
            DataGridStyle();
            BinData();
        }

       
        private void button5_Click(object sender, EventArgs e)
        {
            if (FBillNo == null || FBillNo == "")
            {
                MessageBox.Show("请选择订单", "警告!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button3);
            }
            AbanINStockDetail aisd = new AbanINStockDetail(FBillNo, FEntryID, Fry, FSku, StickLen, FQty, Fdate,this.ID);
            aisd.Show();
            this.Hide();
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            Main2 main = new Main2(this.ID);
            main.Show();
            this.Hide();
        }
      
    }
}